/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"
#include "utils.h"


INT16 _main( mxArray *ima[] )
{   
    void FARTYPE *is;
    INT16 s;
    s = eyelink_get_sample( is ) ;
    if ( s == 1 ){
        isample2struct( *((ISAMPLE *) is), ima );
    } else {
	const mwSize t[] = {0};
	*ima = mxCreateCellArray(0,t);
    }
    return s;
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    double *status;
    mwSize td[2] = {1,1};
        
    /* Verify input arguments. */
    if(nrhs != 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 2 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    if ( nlhs < 2){
        void FARTYPE *isample;
        *status = (double ) eyelink_get_sample( isample );        
    } else if ( nlhs == 2 ) {
        *status = (double ) _main( plhs + 1 );  
    }  
    return;
}
